//
// Created by 17775 on 2024/6/21.
//

#ifndef RAYCI_CROSSSECTION_H
#define RAYCI_CROSSSECTION_H

#include <QWidget>
#include "../qcustomplot.h"
#include <QtConcurrent/QtConcurrent>
#include "../LiveMode/livemode_crosssection_options.h"
#include "../utils/CrossSectionDataReceiveListener.h"


QT_BEGIN_NAMESPACE
namespace Ui { class CrossSection; }
QT_END_NAMESPACE

class CrossSection : public QDockWidget, public CrossSectionDataReceiveListener {
Q_OBJECT

signals:
    void showCrossSectionOptions();
    void stopCrossSectionThread();
    void setXCross();
    void setYCross();
    void setRadial();
    void setArbitrary();
    void setCircular();

public:
    explicit CrossSection(QWidget *parent = nullptr);
    ~CrossSection() override;
    int getOrder() const override {
        return 100;
    }
    void setWindowTitleName(const QString& name);
    void closeEvent(QCloseEvent *event) override;
    static QList<double> convertVectorToQList(const std::vector<float>& vec);
    void receiveMessage(const std::shared_ptr<PowerProfileData<std::vector<float>>>& data) override;
    void closeCrossSection();
    void showAbscissa(bool show);
    void showOrdinate(bool show);
    void rescaleCrossAxes();

private:
    Ui::CrossSection *ui;
    QCustomPlot *customPlot = nullptr;
    QCPTextElement *title = nullptr;
    QMenu *m_contextMenu = nullptr;
    QFutureWatcher<std::pair<QList<double>, QList<double>>> futureWatcher;
    QMutex mutex;
    bool firstRescale = true;
};


#endif //RAYCI_CROSSSECTION_H
